﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Hr.DAL
{
    /// <summary>
    /// 数据访问类Struct_UserDepartRelation。
    /// </summary>
    public class Struct_UserDepartRelation
    {
        public Struct_UserDepartRelation()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(Guid RecordId)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Struct_UserDepartRelation where RecordId=@RecordId ");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            int cmdresult;
            object obj = db.ExecuteScalar(dbCommand);
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(string strWhere)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            StringBuilder strSql = new StringBuilder();
            strSql.AppendFormat("select count(1) from Struct_UserDepartRelation where 1=1 {0} ", strWhere);
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            int cmdresult;
            object obj = db.ExecuteScalar(dbCommand);
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Struct_UserDepartRelation(");
            strSql.Append("RecordId,CityId,City,CompanyId,Company,DepartId,DepartName,UserId,UserCode,UserName,IsBelong,IsRoleA,IsRoleB,IsRoleC,IsRoleD,IsRoleE,IsRoleF,IsRoleG,IsRoleH,ViewPubHouse,ViewPrivHouse,ViewHideHouse,ViewPrivDemand,ViewRealCustomer,ViewFakeCustomer,EditPrimaryHouse,EditNormalHouse,DelTrace,CanProtect,CanLockHouse,ViewLockHouse,ViewChange,CanChangeConfirm,ViewEntrust,CanCancelTrust,UnCancelTrust,CanDelTrust,ViewWatching,EditWatching,EditKey,UseKey,EditKeyUsing,EditTrust,CancelLockHouse,ViewPrivCustomer,EditPubDemand,EditPrivDemand,ViewTelLog,ViewBusiness,ViewHrInfo,ViewHrChange,ViewAttendance,ViewVacation,ViewAnnualLeave,ViewUserLog,DelHouse,EditPubCustomer,EditPrivCustomer,ViewStock,IsControl,Addtime,ShiftPubCustomer,SetPubLevel,ViewCrossPubShareDemand,ViewPubShareDemand,ViewCrossPubShareCustomer,ViewPubShareCustomer,viewtrace,CanUploadPicture,CanDeletePicture,CanPublishHouse)");

            strSql.Append(" values (");
            strSql.Append("@RecordId,@CityId,@City,@CompanyId,@Company,@DepartId,@DepartName,@UserId,@UserCode,@UserName,@IsBelong,@IsRoleA,@IsRoleB,@IsRoleC,@IsRoleD,@IsRoleE,@IsRoleF,@IsRoleG,@IsRoleH,@ViewPubHouse,@ViewPrivHouse,@ViewHideHouse,@ViewPrivDemand,@ViewRealCustomer,@ViewFakeCustomer,@EditPrimaryHouse,@EditNormalHouse,@DelTrace,@CanProtect,@CanLockHouse,@ViewLockHouse,@ViewChange,@CanChangeConfirm,@ViewEntrust,@CanCancelTrust,@UnCancelTrust,@CanDelTrust,@ViewWatching,@EditWatching,@EditKey,@UseKey,@EditKeyUsing,@EditTrust,@CancelLockHouse,@ViewPrivCustomer,@EditPubDemand,@EditPrivDemand,@ViewTelLog,@ViewBusiness,@ViewHrInfo,@ViewHrChange,@ViewAttendance,@ViewVacation,@ViewAnnualLeave,@ViewUserLog,@DelHouse,@EditPubCustomer,@EditPrivCustomer,@ViewStock,@IsControl,@Addtime,@ShiftPubCustomer,@SetPubLevel,@ViewCrossPubShareDemand,@ViewPubShareDemand,@ViewCrossPubShareCustomer,@ViewPubShareCustomer,@viewtrace,@CanUploadPicture,@CanDeletePicture,@CanPublishHouse)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "CityId", DbType.Guid, model.CityId);
            db.AddInParameter(dbCommand, "City", DbType.AnsiString, model.City);
            db.AddInParameter(dbCommand, "CompanyId", DbType.Guid, model.CompanyId);
            db.AddInParameter(dbCommand, "Company", DbType.AnsiString, model.Company);
            db.AddInParameter(dbCommand, "DepartId", DbType.Guid, model.DepartId);
            db.AddInParameter(dbCommand, "DepartName", DbType.AnsiString, model.DepartName);
            db.AddInParameter(dbCommand, "UserId", DbType.Guid, model.UserId);
            db.AddInParameter(dbCommand, "UserCode", DbType.AnsiString, model.UserCode);
            db.AddInParameter(dbCommand, "UserName", DbType.AnsiString, model.UserName);
            db.AddInParameter(dbCommand, "IsBelong", DbType.Boolean, model.IsBelong);
            db.AddInParameter(dbCommand, "IsRoleA", DbType.Boolean, model.IsRoleA);
            db.AddInParameter(dbCommand, "IsRoleB", DbType.Boolean, model.IsRoleB);
            db.AddInParameter(dbCommand, "IsRoleC", DbType.Boolean, model.IsRoleC);
            db.AddInParameter(dbCommand, "IsRoleD", DbType.Boolean, model.IsRoleD);
            db.AddInParameter(dbCommand, "IsRoleE", DbType.Boolean, model.IsRoleE);
            db.AddInParameter(dbCommand, "IsRoleF", DbType.Boolean, model.IsRoleF);
            db.AddInParameter(dbCommand, "IsRoleG", DbType.Boolean, model.IsRoleG);
            db.AddInParameter(dbCommand, "IsRoleH", DbType.Boolean, model.IsRoleH);
            db.AddInParameter(dbCommand, "ViewPubHouse", DbType.Boolean, model.ViewPubHouse);
            db.AddInParameter(dbCommand, "ViewPrivHouse", DbType.Boolean, model.ViewPrivHouse);
            db.AddInParameter(dbCommand, "ViewHideHouse", DbType.Boolean, model.ViewHideHouse);
            //db.AddInParameter(dbCommand, "ViewPubDemand", DbType.Boolean, model.ViewPubDemand);
            db.AddInParameter(dbCommand, "ViewPrivDemand", DbType.Boolean, model.ViewPrivDemand);
            db.AddInParameter(dbCommand, "ViewRealCustomer", DbType.Boolean, model.ViewRealCustomer);
            db.AddInParameter(dbCommand, "ViewFakeCustomer", DbType.Boolean, model.ViewFakeCustomer);
            db.AddInParameter(dbCommand, "EditPrimaryHouse", DbType.Boolean, model.EditPrimaryHouse);
            db.AddInParameter(dbCommand, "EditNormalHouse", DbType.Boolean, model.EditNormalHouse);
            db.AddInParameter(dbCommand, "DelTrace", DbType.Boolean, model.DelTrace);
            db.AddInParameter(dbCommand, "CanProtect", DbType.Boolean, model.CanProtect);
            db.AddInParameter(dbCommand, "CanLockHouse", DbType.Boolean, model.CanLockHouse);
            db.AddInParameter(dbCommand, "ViewLockHouse", DbType.Boolean, model.ViewLockHouse);
            db.AddInParameter(dbCommand, "ViewChange", DbType.Boolean, model.ViewChange);
            db.AddInParameter(dbCommand, "CanChangeConfirm", DbType.Boolean, model.CanChangeConfirm);
            db.AddInParameter(dbCommand, "ViewEntrust", DbType.Boolean, model.ViewEntrust);
            db.AddInParameter(dbCommand, "CanCancelTrust", DbType.Boolean, model.CanCancelTrust);
            db.AddInParameter(dbCommand, "UnCancelTrust", DbType.Boolean, model.UnCancelTrust);
            db.AddInParameter(dbCommand, "CanDelTrust", DbType.Boolean, model.CanDelTrust);
            db.AddInParameter(dbCommand, "ViewWatching", DbType.Boolean, model.ViewWatching);
            db.AddInParameter(dbCommand, "EditWatching", DbType.Boolean, model.EditWatching);
            db.AddInParameter(dbCommand, "EditKey", DbType.Boolean, model.EditKey);
            db.AddInParameter(dbCommand, "UseKey", DbType.Boolean, model.UseKey);
            db.AddInParameter(dbCommand, "EditKeyUsing", DbType.Boolean, model.EditKeyUsing);
            db.AddInParameter(dbCommand, "EditTrust", DbType.Boolean, model.EditTrust);
            db.AddInParameter(dbCommand, "CancelLockHouse", DbType.Boolean, model.CancelLockHouse);
//            db.AddInParameter(dbCommand, "ViewPubCustomer", DbType.Boolean, model.ViewPubCustomer);
            db.AddInParameter(dbCommand, "ViewPrivCustomer", DbType.Boolean, model.ViewPrivCustomer);
            db.AddInParameter(dbCommand, "EditPubDemand", DbType.Boolean, model.EditPubDemand);
            db.AddInParameter(dbCommand, "EditPrivDemand", DbType.Boolean, model.EditPrivDemand);
            db.AddInParameter(dbCommand, "ViewTelLog", DbType.Boolean, model.ViewTelLog);
            db.AddInParameter(dbCommand, "ViewBusiness", DbType.Boolean, model.ViewBusiness);
            db.AddInParameter(dbCommand, "ViewHrInfo", DbType.Boolean, model.ViewHrInfo);
            db.AddInParameter(dbCommand, "ViewHrChange", DbType.Boolean, model.ViewHrChange);
            db.AddInParameter(dbCommand, "ViewAttendance", DbType.Boolean, model.ViewAttendance);
            db.AddInParameter(dbCommand, "ViewVacation", DbType.Boolean, model.ViewVacation);
            db.AddInParameter(dbCommand, "ViewAnnualLeave", DbType.Boolean, model.ViewAnnualLeave);
            db.AddInParameter(dbCommand, "ViewUserLog", DbType.Boolean, model.ViewUserLog);
            db.AddInParameter(dbCommand, "DelHouse", DbType.Boolean, model.DelHouse);
            db.AddInParameter(dbCommand, "EditPubCustomer", DbType.Boolean, model.EditPubCustomer);
            db.AddInParameter(dbCommand, "EditPrivCustomer", DbType.Boolean, model.EditPrivCustomer);
            db.AddInParameter(dbCommand, "ViewStock", DbType.Boolean, model.ViewStock);
            db.AddInParameter(dbCommand, "IsControl", DbType.Boolean, model.IsControl);
            db.AddInParameter(dbCommand, "Addtime", DbType.DateTime, model.Addtime);
            db.AddInParameter(dbCommand, "ShiftPubCustomer", DbType.Boolean, model.ShiftPubCustomer);
            db.AddInParameter(dbCommand, "SetPubLevel", DbType.Boolean, model.SetPubLevel);
            db.AddInParameter(dbCommand, "ViewCrossPubShareDemand", DbType.Boolean, model.ViewCrossPubShareDemand);
            db.AddInParameter(dbCommand, "ViewPubShareDemand", DbType.Boolean, model.ViewPubShareDemand);
            db.AddInParameter(dbCommand, "ViewCrossPubShareCustomer", DbType.Boolean, model.ViewCrossPubShareCustomer);
            db.AddInParameter(dbCommand, "ViewPubShareCustomer", DbType.Boolean, model.ViewPubShareCustomer);
            db.AddInParameter(dbCommand, "viewtrace", DbType.Boolean, model.viewtrace);
            db.AddInParameter(dbCommand, "CanUploadPicture", DbType.Boolean, model.CanUploadPicture);
            db.AddInParameter(dbCommand, "CanDeletePicture", DbType.Boolean, model.CanDeletePicture);
            db.AddInParameter(dbCommand, "CanPublishHouse", DbType.Boolean, model.CanPublishHouse);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Struct_UserDepartRelation set ");
            strSql.Append("CityId=@CityId,");
            strSql.Append("City=@City,");
            strSql.Append("CompanyId=@CompanyId,");
            strSql.Append("Company=@Company,");
            strSql.Append("DepartId=@DepartId,");
            strSql.Append("DepartName=@DepartName,");
            strSql.Append("UserId=@UserId,");
            strSql.Append("UserCode=@UserCode,");
            strSql.Append("UserName=@UserName,");
            strSql.Append("IsBelong=@IsBelong,");
            strSql.Append("IsRoleA=@IsRoleA,");
            strSql.Append("IsRoleB=@IsRoleB,");
            strSql.Append("IsRoleC=@IsRoleC,");
            strSql.Append("IsRoleD=@IsRoleD,");
            strSql.Append("IsRoleE=@IsRoleE,");
            strSql.Append("IsRoleF=@IsRoleF,");
            strSql.Append("IsRoleG=@IsRoleG,");
            strSql.Append("IsRoleH=@IsRoleH,");
            strSql.Append("ViewPubHouse=@ViewPubHouse,");
            strSql.Append("ViewPrivHouse=@ViewPrivHouse,");
            strSql.Append("ViewHideHouse=@ViewHideHouse,");
//            strSql.Append("ViewPubDemand=@ViewPubDemand,");
            strSql.Append("ViewPrivDemand=@ViewPrivDemand,");
            strSql.Append("ViewRealCustomer=@ViewRealCustomer,");
            strSql.Append("ViewFakeCustomer=@ViewFakeCustomer,");
            strSql.Append("EditPrimaryHouse=@EditPrimaryHouse,");
            strSql.Append("EditNormalHouse=@EditNormalHouse,");
            strSql.Append("DelTrace=@DelTrace,");
            strSql.Append("CanProtect=@CanProtect,");
            strSql.Append("CanLockHouse=@CanLockHouse,");
            strSql.Append("ViewLockHouse=@ViewLockHouse,");
            strSql.Append("ViewChange=@ViewChange,");
            strSql.Append("CanChangeConfirm=@CanChangeConfirm,");
            strSql.Append("ViewEntrust=@ViewEntrust,");
            strSql.Append("CanCancelTrust=@CanCancelTrust,");
            strSql.Append("UnCancelTrust=@UnCancelTrust,");
            strSql.Append("CanDelTrust=@CanDelTrust,");
            strSql.Append("ViewWatching=@ViewWatching,");
            strSql.Append("EditWatching=@EditWatching,");
            strSql.Append("EditKey=@EditKey,");
            strSql.Append("UseKey=@UseKey,");
            strSql.Append("EditKeyUsing=@EditKeyUsing,");
            strSql.Append("EditTrust=@EditTrust,");
            strSql.Append("CancelLockHouse=@CancelLockHouse,");
            //strSql.Append("ViewPubCustomer=@ViewPubCustomer,");
            strSql.Append("ViewPrivCustomer=@ViewPrivCustomer,");
            strSql.Append("EditPubDemand=@EditPubDemand,");
            strSql.Append("EditPrivDemand=@EditPrivDemand,");
            strSql.Append("ViewTelLog=@ViewTelLog,");
            strSql.Append("ViewBusiness=@ViewBusiness,");
            strSql.Append("ViewHrInfo=@ViewHrInfo,");
            strSql.Append("ViewHrChange=@ViewHrChange,");
            strSql.Append("ViewAttendance=@ViewAttendance,");
            strSql.Append("ViewVacation=@ViewVacation,");
            strSql.Append("ViewAnnualLeave=@ViewAnnualLeave,");
            strSql.Append("ViewUserLog=@ViewUserLog,");
            strSql.Append("DelHouse=@DelHouse,");
            strSql.Append("EditPubCustomer=@EditPubCustomer,");
            strSql.Append("EditPrivCustomer=@EditPrivCustomer,");
            strSql.Append("ViewStock=@ViewStock,");
            strSql.Append("IsControl=@IsControl,");
            strSql.Append("Addtime=@Addtime,");
            strSql.Append("ShiftPubCustomer=@ShiftPubCustomer,");
            strSql.Append("SetPubLevel=@SetPubLevel,");
            strSql.Append("ViewCrossPubShareDemand=@ViewCrossPubShareDemand,");
            strSql.Append("ViewPubShareDemand=@ViewPubShareDemand,");
            strSql.Append("ViewCrossPubShareCustomer=@ViewCrossPubShareCustomer,");
            strSql.Append("ViewPubShareCustomer=@ViewPubShareCustomer,");
            strSql.Append("viewtrace=@viewtrace,");
            strSql.Append("CanUploadPicture=@CanUploadPicture,");
            strSql.Append("CanDeletePicture=@CanDeletePicture,");
            strSql.Append("CanPublishHouse=@CanPublishHouse");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "CityId", DbType.Guid, model.CityId);
            db.AddInParameter(dbCommand, "City", DbType.AnsiString, model.City);
            db.AddInParameter(dbCommand, "CompanyId", DbType.Guid, model.CompanyId);
            db.AddInParameter(dbCommand, "Company", DbType.AnsiString, model.Company);
            db.AddInParameter(dbCommand, "DepartId", DbType.Guid, model.DepartId);
            db.AddInParameter(dbCommand, "DepartName", DbType.AnsiString, model.DepartName);
            db.AddInParameter(dbCommand, "UserId", DbType.Guid, model.UserId);
            db.AddInParameter(dbCommand, "UserCode", DbType.AnsiString, model.UserCode);
            db.AddInParameter(dbCommand, "UserName", DbType.AnsiString, model.UserName);
            db.AddInParameter(dbCommand, "IsBelong", DbType.Boolean, model.IsBelong);
            db.AddInParameter(dbCommand, "IsRoleA", DbType.Boolean, model.IsRoleA);
            db.AddInParameter(dbCommand, "IsRoleB", DbType.Boolean, model.IsRoleB);
            db.AddInParameter(dbCommand, "IsRoleC", DbType.Boolean, model.IsRoleC);
            db.AddInParameter(dbCommand, "IsRoleD", DbType.Boolean, model.IsRoleD);
            db.AddInParameter(dbCommand, "IsRoleE", DbType.Boolean, model.IsRoleE);
            db.AddInParameter(dbCommand, "IsRoleF", DbType.Boolean, model.IsRoleF);
            db.AddInParameter(dbCommand, "IsRoleG", DbType.Boolean, model.IsRoleG);
            db.AddInParameter(dbCommand, "IsRoleH", DbType.Boolean, model.IsRoleH);
            db.AddInParameter(dbCommand, "ViewPubHouse", DbType.Boolean, model.ViewPubHouse);
            db.AddInParameter(dbCommand, "ViewPrivHouse", DbType.Boolean, model.ViewPrivHouse);
            db.AddInParameter(dbCommand, "ViewHideHouse", DbType.Boolean, model.ViewHideHouse);
//            db.AddInParameter(dbCommand, "ViewPubDemand", DbType.Boolean, model.ViewPubDemand);
            db.AddInParameter(dbCommand, "ViewPrivDemand", DbType.Boolean, model.ViewPrivDemand);
            db.AddInParameter(dbCommand, "ViewRealCustomer", DbType.Boolean, model.ViewRealCustomer);
            db.AddInParameter(dbCommand, "ViewFakeCustomer", DbType.Boolean, model.ViewFakeCustomer);
            db.AddInParameter(dbCommand, "EditPrimaryHouse", DbType.Boolean, model.EditPrimaryHouse);
            db.AddInParameter(dbCommand, "EditNormalHouse", DbType.Boolean, model.EditNormalHouse);
            db.AddInParameter(dbCommand, "DelTrace", DbType.Boolean, model.DelTrace);
            db.AddInParameter(dbCommand, "CanProtect", DbType.Boolean, model.CanProtect);
            db.AddInParameter(dbCommand, "CanLockHouse", DbType.Boolean, model.CanLockHouse);
            db.AddInParameter(dbCommand, "ViewLockHouse", DbType.Boolean, model.ViewLockHouse);
            db.AddInParameter(dbCommand, "ViewChange", DbType.Boolean, model.ViewChange);
            db.AddInParameter(dbCommand, "CanChangeConfirm", DbType.Boolean, model.CanChangeConfirm);
            db.AddInParameter(dbCommand, "ViewEntrust", DbType.Boolean, model.ViewEntrust);
            db.AddInParameter(dbCommand, "CanCancelTrust", DbType.Boolean, model.CanCancelTrust);
            db.AddInParameter(dbCommand, "UnCancelTrust", DbType.Boolean, model.UnCancelTrust);
            db.AddInParameter(dbCommand, "CanDelTrust", DbType.Boolean, model.CanDelTrust);
            db.AddInParameter(dbCommand, "ViewWatching", DbType.Boolean, model.ViewWatching);
            db.AddInParameter(dbCommand, "EditWatching", DbType.Boolean, model.EditWatching);
            db.AddInParameter(dbCommand, "EditKey", DbType.Boolean, model.EditKey);
            db.AddInParameter(dbCommand, "UseKey", DbType.Boolean, model.UseKey);
            db.AddInParameter(dbCommand, "EditKeyUsing", DbType.Boolean, model.EditKeyUsing);
            db.AddInParameter(dbCommand, "EditTrust", DbType.Boolean, model.EditTrust);
            db.AddInParameter(dbCommand, "CancelLockHouse", DbType.Boolean, model.CancelLockHouse);
            //db.AddInParameter(dbCommand, "ViewPubCustomer", DbType.Boolean, model.ViewPubCustomer);
            db.AddInParameter(dbCommand, "ViewPrivCustomer", DbType.Boolean, model.ViewPrivCustomer);
            db.AddInParameter(dbCommand, "EditPubDemand", DbType.Boolean, model.EditPubDemand);
            db.AddInParameter(dbCommand, "EditPrivDemand", DbType.Boolean, model.EditPrivDemand);
            db.AddInParameter(dbCommand, "ViewTelLog", DbType.Boolean, model.ViewTelLog);
            db.AddInParameter(dbCommand, "ViewBusiness", DbType.Boolean, model.ViewBusiness);
            db.AddInParameter(dbCommand, "ViewHrInfo", DbType.Boolean, model.ViewHrInfo);
            db.AddInParameter(dbCommand, "ViewHrChange", DbType.Boolean, model.ViewHrChange);
            db.AddInParameter(dbCommand, "ViewAttendance", DbType.Boolean, model.ViewAttendance);
            db.AddInParameter(dbCommand, "ViewVacation", DbType.Boolean, model.ViewVacation);
            db.AddInParameter(dbCommand, "ViewAnnualLeave", DbType.Boolean, model.ViewAnnualLeave);
            db.AddInParameter(dbCommand, "ViewUserLog", DbType.Boolean, model.ViewUserLog);
            db.AddInParameter(dbCommand, "DelHouse", DbType.Boolean, model.DelHouse);
            db.AddInParameter(dbCommand, "EditPubCustomer", DbType.Boolean, model.EditPubCustomer);
            db.AddInParameter(dbCommand, "EditPrivCustomer", DbType.Boolean, model.EditPrivCustomer);
            db.AddInParameter(dbCommand, "ViewStock", DbType.Boolean, model.ViewStock);
            db.AddInParameter(dbCommand, "IsControl", DbType.Boolean, model.IsControl);
            db.AddInParameter(dbCommand, "Addtime", DbType.DateTime, model.Addtime);
            db.AddInParameter(dbCommand, "ShiftPubCustomer", DbType.Boolean, model.ShiftPubCustomer);
            db.AddInParameter(dbCommand, "SetPubLevel", DbType.Boolean, model.SetPubLevel);
            db.AddInParameter(dbCommand, "ViewCrossPubShareDemand", DbType.Boolean, model.ViewCrossPubShareDemand);
            db.AddInParameter(dbCommand, "ViewPubShareDemand", DbType.Boolean, model.ViewPubShareDemand);
            db.AddInParameter(dbCommand, "ViewCrossPubShareCustomer", DbType.Boolean, model.ViewCrossPubShareCustomer);
            db.AddInParameter(dbCommand, "ViewPubShareCustomer", DbType.Boolean, model.ViewPubShareCustomer);
            db.AddInParameter(dbCommand, "viewtrace", DbType.Boolean, model.viewtrace);
            db.AddInParameter(dbCommand, "CanUploadPicture", DbType.Boolean, model.CanUploadPicture);
            db.AddInParameter(dbCommand, "CanDeletePicture", DbType.Boolean, model.CanDeletePicture);
            db.AddInParameter(dbCommand, "CanPublishHouse", DbType.Boolean, model.CanPublishHouse);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Struct_UserDepartRelation ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation GetModel(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CityId,City,CompanyId,Company,DepartId,DepartName,UserId,UserCode,UserName,IsBelong,IsRoleA,IsRoleB,IsRoleC,IsRoleD,IsRoleE,IsRoleF,IsRoleG,IsRoleH,ViewPubHouse,ViewPrivHouse,ViewHideHouse,ViewPrivDemand,ViewRealCustomer,ViewFakeCustomer,EditPrimaryHouse,EditNormalHouse,DelTrace,CanProtect,CanLockHouse,ViewLockHouse,ViewChange,CanChangeConfirm,ViewEntrust,CanCancelTrust,UnCancelTrust,CanDelTrust,ViewWatching,EditWatching,EditKey,UseKey,EditKeyUsing,EditTrust,CancelLockHouse,ViewPrivCustomer,EditPubDemand,EditPrivDemand,ViewTelLog,ViewBusiness,ViewHrInfo,ViewHrChange,ViewAttendance,ViewVacation,ViewAnnualLeave,ViewUserLog,DelHouse,EditPubCustomer,EditPrivCustomer,ViewStock,IsControl,Addtime,ShiftPubCustomer,SetPubLevel,ViewCrossPubShareDemand,ViewPubShareDemand,ViewCrossPubShareCustomer,ViewPubShareCustomer,viewtrace,CanUploadPicture,CanDeletePicture,CanPublishHouse from Struct_UserDepartRelation ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CityId,City,CompanyId,Company,DepartId,DepartName,UserId,UserCode,UserName,IsBelong,IsRoleA,IsRoleB,IsRoleC,IsRoleD,IsRoleE,IsRoleF,IsRoleG,IsRoleH,ViewPubHouse,ViewPrivHouse,ViewHideHouse,ViewPrivDemand,ViewRealCustomer,ViewFakeCustomer,EditPrimaryHouse,EditNormalHouse,DelTrace,CanProtect,CanLockHouse,ViewLockHouse,ViewChange,CanChangeConfirm,ViewEntrust,CanCancelTrust,UnCancelTrust,CanDelTrust,ViewWatching,EditWatching,EditKey,UseKey,EditKeyUsing,EditTrust,CancelLockHouse,ViewPrivCustomer,EditPubDemand,EditPrivDemand,ViewTelLog,ViewBusiness,ViewHrInfo,ViewHrChange,ViewAttendance,ViewVacation,ViewAnnualLeave,ViewUserLog,DelHouse,EditPubCustomer,EditPrivCustomer,ViewStock,IsControl,Addtime,ShiftPubCustomer,SetPubLevel,ViewCrossPubShareDemand,ViewPubShareDemand,ViewCrossPubShareCustomer,ViewPubShareCustomer,viewtrace,CanUploadPicture,CanDeletePicture,CanPublishHouse ");
            strSql.Append(" FROM Struct_UserDepartRelation ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 执行SQL（返回影响行数）
        /// </summary>
        public static bool ExecuteSQL(string strSQL)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main");
            int count = db.ExecuteNonQuery(CommandType.Text, strSQL);
            if (count > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 执行查询SQL（返回首记录）
        /// </summary>
        public static bool SearchSQL(string strSQL)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            int count = (int)db.ExecuteScalar(CommandType.Text, strSQL);
            if (count > 0)
                return true;
            else
                return false;
        }

        /// 分页获取数据列表
        /// </summary>
        public static DataSet GetList(int PageIndex, int PageSize, String OrderField, string TableName, string StrWhere, string FieldList, string TableFieldList, bool DoCount)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            DbCommand dbCommand = db.GetStoredProcCommand("PagerMultiTable");



            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "OrderField", DbType.AnsiString, OrderField);
            db.AddInParameter(dbCommand, "TableName", DbType.AnsiString, TableName);
            db.AddInParameter(dbCommand, "StrWhere", DbType.AnsiString, StrWhere);
            db.AddInParameter(dbCommand, "FieldList", DbType.AnsiString, FieldList);
            db.AddInParameter(dbCommand, "TableFieldList", DbType.AnsiString, TableFieldList);
            db.AddInParameter(dbCommand, "DoCount", DbType.Boolean, DoCount);
            return db.ExecuteDataSet(dbCommand);
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CityId,City,CompanyId,Company,DepartId,DepartName,UserId,UserCode,UserName,IsBelong,IsRoleA,IsRoleB,IsRoleC,IsRoleD,IsRoleE,IsRoleF,IsRoleG,IsRoleH,ViewPubHouse,ViewPrivHouse,ViewHideHouse,ViewPrivDemand,ViewRealCustomer,ViewFakeCustomer,EditPrimaryHouse,EditNormalHouse,DelTrace,CanProtect,CanLockHouse,ViewLockHouse,ViewChange,CanChangeConfirm,ViewEntrust,CanCancelTrust,UnCancelTrust,CanDelTrust,ViewWatching,EditWatching,EditKey,UseKey,EditKeyUsing,EditTrust,CancelLockHouse,ViewPrivCustomer,EditPubDemand,EditPrivDemand,ViewTelLog,ViewBusiness,ViewHrInfo,ViewHrChange,ViewAttendance,ViewVacation,ViewAnnualLeave,ViewUserLog,DelHouse,EditPubCustomer,EditPrivCustomer,ViewStock,IsControl,Addtime,ShiftPubCustomer,SetPubLevel,ViewCrossPubShareDemand,ViewPubShareDemand,ViewCrossPubShareCustomer,ViewPubShareCustomer,viewtrace,CanUploadPicture,CanDeletePicture,CanPublishHouse ");
            strSql.Append(" FROM Struct_UserDepartRelation ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation> list = new List<Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetTable(string sql)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            return db.ExecuteDataSet(CommandType.Text, sql);
        }

        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation model = new Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation();
            object ojb;
            ojb = dataReader["RecordId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecordId = new Guid(ojb.ToString());
            }
            ojb = dataReader["CityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CityId = new Guid(ojb.ToString());
            }
            model.City = dataReader["City"].ToString();
            ojb = dataReader["CompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CompanyId = new Guid(ojb.ToString());
            }
            model.Company = dataReader["Company"].ToString();
            ojb = dataReader["DepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DepartId = new Guid(ojb.ToString());
            }
            model.DepartName = dataReader["DepartName"].ToString();
            ojb = dataReader["UserId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UserId = new Guid(ojb.ToString());
            }
            model.UserCode = dataReader["UserCode"].ToString();
            model.UserName = dataReader["UserName"].ToString();
            ojb = dataReader["IsBelong"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsBelong = (bool)ojb;
            }
            ojb = dataReader["IsRoleA"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsRoleA = (bool)ojb;
            }
            ojb = dataReader["IsRoleB"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsRoleB = (bool)ojb;
            }
            ojb = dataReader["IsRoleC"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsRoleC = (bool)ojb;
            }
            ojb = dataReader["IsRoleD"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsRoleD = (bool)ojb;
            }
            ojb = dataReader["IsRoleE"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsRoleE = (bool)ojb;
            }
            ojb = dataReader["IsRoleF"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsRoleF = (bool)ojb;
            }
            ojb = dataReader["IsRoleG"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsRoleG = (bool)ojb;
            }
            ojb = dataReader["IsRoleH"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsRoleH = (bool)ojb;
            }
            ojb = dataReader["ViewPubHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPubHouse = (bool)ojb;
            }
            ojb = dataReader["ViewPrivHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPrivHouse = (bool)ojb;
            }
            ojb = dataReader["ViewHideHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewHideHouse = (bool)ojb;
            }
            //ojb = dataReader["ViewPubDemand"];
            //if (ojb != null && ojb != DBNull.Value)
            //{
            //    model.ViewPubDemand = (bool)ojb;
            //}
            ojb = dataReader["ViewPrivDemand"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPrivDemand = (bool)ojb;
            }
            ojb = dataReader["ViewRealCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewRealCustomer = (bool)ojb;
            }
            ojb = dataReader["ViewFakeCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewFakeCustomer = (bool)ojb;
            }
            ojb = dataReader["EditPrimaryHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditPrimaryHouse = (bool)ojb;
            }
            ojb = dataReader["EditNormalHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditNormalHouse = (bool)ojb;
            }
            ojb = dataReader["DelTrace"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DelTrace = (bool)ojb;
            }
            ojb = dataReader["CanProtect"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanProtect = (bool)ojb;
            }
            ojb = dataReader["CanLockHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanLockHouse = (bool)ojb;
            }
            ojb = dataReader["ViewLockHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewLockHouse = (bool)ojb;
            }
            ojb = dataReader["ViewChange"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewChange = (bool)ojb;
            }
            ojb = dataReader["CanChangeConfirm"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanChangeConfirm = (bool)ojb;
            }
            ojb = dataReader["ViewEntrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewEntrust = (bool)ojb;
            }
            ojb = dataReader["CanCancelTrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanCancelTrust = (bool)ojb;
            }
            ojb = dataReader["UnCancelTrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UnCancelTrust = (bool)ojb;
            }
            ojb = dataReader["CanDelTrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanDelTrust = (bool)ojb;
            }
            ojb = dataReader["ViewWatching"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewWatching = (bool)ojb;
            }
            ojb = dataReader["EditWatching"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditWatching = (bool)ojb;
            }
            ojb = dataReader["EditKey"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditKey = (bool)ojb;
            }
            ojb = dataReader["UseKey"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UseKey = (bool)ojb;
            }
            ojb = dataReader["EditKeyUsing"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditKeyUsing = (bool)ojb;
            }
            ojb = dataReader["EditTrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditTrust = (bool)ojb;
            }
            ojb = dataReader["CancelLockHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CancelLockHouse = (bool)ojb;
            }
            //ojb = dataReader["ViewPubCustomer"];
            //if (ojb != null && ojb != DBNull.Value)
            //{
            //    model.ViewPubCustomer = (bool)ojb;
            //}
            ojb = dataReader["ViewPrivCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPrivCustomer = (bool)ojb;
            }
            ojb = dataReader["EditPubDemand"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditPubDemand = (bool)ojb;
            }
            ojb = dataReader["EditPrivDemand"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditPrivDemand = (bool)ojb;
            }
            ojb = dataReader["ViewTelLog"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewTelLog = (bool)ojb;
            }
            ojb = dataReader["ViewBusiness"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewBusiness = (bool)ojb;
            }
            ojb = dataReader["ViewHrInfo"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewHrInfo = (bool)ojb;
            }
            ojb = dataReader["ViewHrChange"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewHrChange = (bool)ojb;
            }
            ojb = dataReader["ViewAttendance"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewAttendance = (bool)ojb;
            }
            ojb = dataReader["ViewVacation"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewVacation = (bool)ojb;
            }
            ojb = dataReader["ViewAnnualLeave"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewAnnualLeave = (bool)ojb;
            }
            ojb = dataReader["ViewUserLog"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewUserLog = (bool)ojb;
            }
            ojb = dataReader["DelHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DelHouse = (bool)ojb;
            }
            ojb = dataReader["EditPubCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditPubCustomer = (bool)ojb;
            }
            ojb = dataReader["EditPrivCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EditPrivCustomer = (bool)ojb;
            }
            ojb = dataReader["ViewStock"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewStock = (bool)ojb;
            }
            ojb = dataReader["IsControl"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsControl = (bool)ojb;
            }
            ojb = dataReader["Addtime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Addtime = (DateTime)ojb;
            }
            ojb = dataReader["ShiftPubCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ShiftPubCustomer = (bool)ojb;
            }
            ojb = dataReader["SetPubLevel"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.SetPubLevel = (bool)ojb;
            }
            ojb = dataReader["ViewCrossPubShareDemand"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewCrossPubShareDemand = (bool)ojb;
            }
            ojb = dataReader["ViewPubShareDemand"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPubShareDemand = (bool)ojb;
            }
            ojb = dataReader["ViewCrossPubShareCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewCrossPubShareCustomer = (bool)ojb;
            }
            ojb = dataReader["ViewPubShareCustomer"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ViewPubShareCustomer = (bool)ojb;
            }
            ojb = dataReader["viewtrace"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.viewtrace = (bool)ojb;
            }
            ojb = dataReader["CanUploadPicture"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanUploadPicture = (bool)ojb;
            }
            ojb = dataReader["CanDeletePicture"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanDeletePicture = (bool)ojb;
            }
            ojb = dataReader["CanPublishHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CanPublishHouse = (bool)ojb;
            }
            return model;
        }

        #endregion  成员方法
    }
}

